package com.jie.controller;

import com.jie.entity.SportFile;
import com.jie.po.rep.FileUploadResponse;
import com.jie.po.rep.MultipartUploadCreateResponse;
import com.jie.po.req.CompleteMultipartUploadRequest;
import com.jie.po.req.MultipartUploadCreateRequest;
import com.jie.response.RespBean;
import com.jie.service.ISportFileService;
import com.jie.service.impl.FileService;
import com.jie.store.context.UploadStrategyContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: 杰
 * @Project :net-disk
 * @DateTime: 2024/5/29 14:22
 **/
@Api(tags = "系统上传文件信息")
@RestController
@RequestMapping("/user-exercise")
@RequiredArgsConstructor
public class SportFileController {
    private final FileService fileService;
    private final ISportFileService sportFileService;
    @ApiOperation(value = "上传文件", notes = "上传文件，上传后返回文件表id")
    @PostMapping("/file/upload")
    public RespBean<String> uploadFile(MultipartFile file) {
        //上传文件
        Integer id=sportFileService.uploadFile(file);
        return RespBean.success("文件id",id);
    }
    //根据文件表id获取文件信息
    @ApiOperation(value = "获取文件信息", notes = "根据文件id来获取")
    @PostMapping("/getFileById/{fileId}")
    public RespBean<?> uploadFile(@PathVariable("fileId") Integer fileId) {
        //上传文件
        SportFile sportFile = sportFileService.getById(fileId);
        return RespBean.success("文件信息内容",sportFile);
    }
    //删除文件表信息

    //修改文件表信息
    @ApiOperation("创建分片上传 ")
    @PostMapping("/multipart/create")
    public MultipartUploadCreateResponse createMultipartUpload(
            @RequestBody
            @Validated
            MultipartUploadCreateRequest multipartUploadCreateRequest
    ) {
        return fileService.createMultipartUpload(multipartUploadCreateRequest);
    }

    @ApiOperation("合并分片")
    @PostMapping("/multipart/complete")
    public FileUploadResponse completeMultipartUpload(
            @RequestBody
            @Validated
            CompleteMultipartUploadRequest uploadRequest
    ) {
        return fileService.completeMultipartUpload(uploadRequest);
    }
}
